<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/6/9
  Time: 22:05
  专区商品表
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
    <script src="../../layui-v2.4.5/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../layui-v2.4.5/layui/css/layui.css" media="all">
</head>
<body>
<input type="hidden" id="prefectureId" value="${prefectureId}">
<div class="layui-form">
    <form class="layui-form" action="">
        <table class="layui-table" >
            <thead>
            <tr>
                <th>名称</th>
                <th>操作</th>
            </tr>

            </thead>
            <tbody>
            <c:forEach items="${pageUtil.list}" var="rl">
                <tr>
                    <td>${rl.name}</td>
                    <td >

                        <div class="layui-form-item">

                            <div class="layui-input-block">
                                <input type="checkbox" name="switch" <c:if test="${prefectureId eq rl.prefectureId}">checked</c:if>  lay-filter="guanlian" lay-text="关联|取消关联" lay-skin="switch" value="${rl.ticketId}">
                            </div>
                        </div>

                    </td>

                </tr>
            </c:forEach>
            </tbody>
        </table>
    </form>


    <div id="page"></div>
    <script>
        function setSlide(id){
            layui.use('layer',function () {
                layer.open({
                    type: 2,
                    area: ['80%', '80%'],
                    offset: '20px',
                    shadeClose:true,
                    content: '/shop/toCommoditySlideShow?commodity='+id,
                    end:function () {
                        console.log("页面要刷新");
                        window.location.reload();
                    }
                });
            });
        }
        layui.use(['laypage', 'layer'], function(){
            var laypage = layui.laypage
                ,layer = layui.layer;

            //完整功能
            laypage.render({
                elem: 'page'
                ,count: ${pageUtil.totalRows}
                ,curr:${pageUtil.currentPage}
                ,hash:true
                ,limits:false
                ,layout: ['count', 'prev', 'page', 'next',  'refresh', 'skip']
                ,jump: function(obj,first){
                    console.log(obj);
                    //首次不执行
                    if(!first){
                        //do something
                        window.location.href="/shop/prefectureCommodity?prefectureId=${prefectureId}&page="+obj.curr+"&limit="+obj.limit+"&key=${key}";
                    }

                }
            });

        });


    </script>
</div>
<script>


    layui.use('form', function(){

        var form = layui.form;

        form.on('switch(guanlian)', function(data){
            console.log(data.elem); //得到checkbox原始DOM对象
            console.log(data.elem.checked); //开关是否开启，true或者false
            //console.log(data.value); //开关value值，也可以通过data.elem.value得到
            //console.log(data.othis); //得到美化后的DOM对象

            $.ajax({
                url:'/shop/upPrefectureCommodity',
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:{
                    prefectureId:"${prefectureId}",
                    state:data.elem.checked,
                    ticketId:data.value
                },
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){

                },
                success:function(reData){
                    if (""!=reData){
                        layer.alert("保存成功", {icon: 6},function (index) {
                            // 获得frame索引
                            //window.location.reload();
                            layer.close(index);
                        });
                    }else {
                        layer.alert("保存失败", {icon: 5});
                    }
                },
                error:function(xhr,textStatus){
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete:function(){
                    //console.log('结束')
                }
            });

        });

    });














</script>



</body>
</html>
